// pages/expert-problem/index.js
const config = require('../../serverUtils/config.js');
const http = require('../../serverUtils/httputils.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    pageNo: 1,
    pageSize: 10,
    listData: [],
    loading: false,
    total: 0,
    popVisible: false,
    listItem: {},
    anserData: []
  },
  showDetail(e) {
    console.log('展示详情', e);
    const knowledgeid = e.currentTarget.dataset?.id
    this.setData({
      popVisible: true,
      listItem: this.data.listData.find(item => (item.id === knowledgeid))
    })
    http.getRequest(
      null,
      config.getProblemDetailApi, {
        knowledgeid,
      },
      (res) => {
        this.setData({
          anserData: res.data
        })
        console.log("获取数据:", res)
      },
      (err) => {},
    )
  },
  lower() {
    if (!this.data.loading && Math.ceil(this.data.total / this.data.pageSize) > this.data.pageNo) {
      //加载更多，这里做下延时加载
      // setTimeout(function () {
      this.setData({
        pageNo: this.data.pageNo + 1
      })
      this.getListData()
      // }, 2000)
    }
  },
  getListData() {
    this.setData({
      loading: true
    })
    http.getRequest(
      null,
      config.getProblemListApi, {
        current: this.data.pageNo,
        size: this.data.pageSize,
      }, // TODO 这个quickDate代表什么？
      (res) => {
        this.setData({
          listData: [...this.data.listData, ...res.data.records],
          loading: false,
          total: res.data.total
        })
        console.log("获取数据:", res)
      },
      (err) => {},
    )
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getListData()
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    this.setData({
      pageNo: 1,
      warnList: [],
      total: 0
    })
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  }
})